package com.example.provider.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {

    @PostMapping("/test1")
    public String test1(HelloUser helloUser, HttpServletRequest request){
        String name = helloUser.getName();
        String name2 = request.getParameter("name");
        return name + " " + name2;
    }
    @PostMapping("/test2")
    public String test2(@RequestBody HelloUser helloUser){
        String name = helloUser.getName();
        return name + " " + name;
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

    @GetMapping("/hellowithparams")
    public String hellowithparams(@RequestParam String name) {
        return "hello " + name;
    }

    @PostMapping("/hellowithparamspost")
    public String hellowithparamspost(@RequestBody HelloUser helloUser, @RequestHeader("Content-Type") String contentType) {
        return "post: hello " + helloUser.getName() + " --- " + contentType;
    }

    @PostMapping("/file")
    public String file(@RequestParam("file") MultipartFile multipartFile) {
        return "file " + multipartFile.getOriginalFilename();
    }

    public static class HelloUser {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }


}
